package com.mdy.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.mdy.mapper.DeptMapper;
import com.mdy.model.Dept;

@RestController
@RequestMapping("/dept.do")
public class DeptCtrl {
	@Resource
	private DeptMapper mapper;
	
	@RequestMapping
	public boolean remove(@PathVariable("id") int id) {
		try {
			this.mapper.delete(id);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		
		
		
	}
	@RequestMapping("/save")
	public boolean save(Dept bean) {
		
		try {
			if(bean.getId()>0) {
				this.mapper.update(bean);
			}else {
				
				this.mapper.insert(bean);
			}
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
			   
		}
		
		
		
	}
	@RequestMapping("/query")
	public List<Dept> query(){
		return this.mapper.selectAll();
		
		
	}
	@RequestMapping("/get/{id}")
	public Dept get(@PathVariable("id") int id) {
		
		return this.mapper.selectOne(id);
		
		
	}
	
	
	
	
	
}
